﻿package com.eitb.programas.olentzero09.objetos{
	import flash.events.*;
	import flash.display.*;
	
	import com.eitb.util.*;
	import com.eitb.programas.olentzero09.*;
	
	public class InfoText extends MovieClip {
		private static const gravedad:Number=-0.05;
		private var velocidad:Number;
		private var limites:Object;
		private var info:String;
		

		public function InfoText():void {
			this.velocidad = 0;
			this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
		}
		
		public function initLimites(limites:Object):void {
			this.limites = limites;
		}
		
		public function initPosition(x:Number, y:Number):void {
			this.x = x;
			this.y = y;
			trace(this.x +"_"+ this.y);
		}
		
		public function initInfo(info:String):void {
			this.info = info;
			this.infoTxt.text = this.info;
		}
		public function onEnterFrame(evt:Event):void {
			var espacio:Number = this.velocidad + InfoText.gravedad * 0.5;
			this.y+=espacio;
			trace(this.y);
			this.velocidad=espacio;
			if (this.isMuerto()) {
				this.finalize();
			}
		}
		
		private function isMuerto():Boolean {
			return (this.y < this.limites.y);
		}
		
		public function finalize():void {
			try {
				this.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
				this.parent.removeChild(this);
			} catch (e:Error) {
				trace(e);
			}
		}
	}
}